package Gather.ImmutableGather;

import java.util.Map;
import java.util.Set;

/**
 * ClassName:Gather004
 * Package:Gather.ImmutableGather
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/23-20:40
 * @Version:v1.0
 */
public class Gather004 {
    /*创建Map的不可集合
     *
     * "张三","南京","李四","北京","王五","上海",
     * "赵六","广州","孙七","深圳","周八","杭州",
     * "吴九","宁波","郑十","苏州","刘一","无锡",
     * "陈二","嘉兴"
     *
     *
     * 细节：
     * 1.键是不能重复的
     * 2.Map里面的of方法,参数是有限的,最多只能传递20个参数,10个键值对
     * 3.如果我们要传递多个键值对对象,它的数量大于10个,在Map集合中还有一个方法ofEntries*/
    public static void main(String[] args) {
        Map<String, String> map = Map.of("张三", "南京", "李四", "北京", "王五", "上海",
                "赵六", "广州", "孙七", "深圳", "周八", "杭州",
                "吴九", "宁波", "郑十", "苏州", "刘一", "无锡",
                "陈二", "嘉兴");

        System.out.println("Lambda表达式遍历");
        map.forEach((key, value) -> System.out.println(key + "=" + value));

        System.out.println("增强for遍历");
        Set<String> keys = map.keySet();
        for (String key : keys) {
            String value = map.get(key);
            System.out.println(key+"="+value);
        }

        //获得键值对对象
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"="+value);
        }


    }

}
